<?php
/**
 * Created by PhpStorm
 * USER:  Zhaoys
 * Date:  2024/3/11
 */

if (!function_exists('response')) {
    function response($content = '')
    {
        $response = new Laminas\Diactoros\Response;
        $response->getBody()->write($content);
        return $response;
    }
}

if (!function_exists('app')) {
    function app($server = null)
    {
        $container = $GLOBALS['container']; # 使用超全局函数获取 container 对象
        if ($server) {
            return $container->get($server); # 获取 container 容器中注册过的服务
        }

        return $container; # 服务不存在则返回容器对象

    }
}


if (!function_exists('view')) {
    function view($tql, $data)
    {
        $twig = app('twig'); # 上面定义的 app 函数，获取容器服务
        $content = $twig->render($tql, $data);
        return response($content); # 定义的响应函数
    }
}


if (!function_exists('base_path')){
    function base_path($path = ''){
        return __DIR__ . ($path?DIRECTORY_SEPARATOR.$path:'');
    }
}

if (!function_exists('public_path')){
    function public_path($path = ''){
        return base_path('public') . ($path?DIRECTORY_SEPARATOR.$path:'');
    }
}
if (!function_exists('storage_path')) {
    function storage_path($path = '')
    {
        return base_path('storage') . ($path ? DIRECTORY_SEPARATOR . $path : '');
    }
}